
<%@page import="qldc.pm.qlktcsdldc.data.UtilsData"%>
<%@page import="qldc.pm.qtht.dmdc.utils.DiaChiUtils"%>
<%@page import="qldc.pm.qlktcsdldc.dto.LichSuDTO"%>
<%@page import="qldc.pm.qlktcsdldc.utils.Utils"%>
<%@page import="qldc.pm.qlktcsdldc.service.NguoiDungLocalServiceUtil"%>
<%@page import="qldc.pm.qlktcsdldc.model.NguoiDung"%>
<%@page import="qldc.pm.qlktcsdldc.service.LichSuCongDanLocalServiceUtil"%>
<%@page import="qldc.pm.qlktcsdldc.model.LichSuCongDan"%>
<%@page import="qldc.pm.csdl.cd90.service.CongDanDTOLocalServiceUtil"%>
<%@page import="qldc.pm.csdl.cd90.model.dto.CongDanDTO"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qlktcsdldc.actions.ActionHandlerConstant"%>
<%@page import="qldc.pm.qlktcsdldc.emun.ThongTinThayDoiEnum"%>
<%@ include file="../init.jsp"%>

<%
	String soDinhDanhCaNhan = ParamUtil.getString(request, "soDinhDanhCaNhan");
	System.out.println("xem lich su thay doi : soDinhDanhCaNhan: >>>"+soDinhDanhCaNhan);
	
	String redirectURL = ParamUtil.getString(request, "redirect");
	
	PortletURL backURL = renderResponse.createRenderURL();
	backURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_dan_cu.jsp");
	backURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLDC_MAN_HINH_CHINH);
	backURL.setParameter("redirect", redirectURL);
	
%>

<portlet:actionURL var="QLDC_LichSuThayDoiURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="QLDC_LichSuThayDoiAction" />
	<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>"/>
	<portlet:param name="redirect" value="<%=backURL.toString()%>" />
</portlet:actionURL>
<%-- <portlet:actionURL var="LichSuThayDoi_XuatVanBanURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="LichSuThayDoi_XuatVanBan" />
	<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>"/>
	<portlet:param name="redirect" value="<%=redirectURL%>" />
</portlet:actionURL>

<portlet:renderURL var="LichSuThayDoi_thoatURL" windowState="<%= String.valueOf(WindowState.NORMAL) %>">
	<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_dan_cu.jsp" />
	<portlet:param name="tabs1" value="<%= QLKTCSDLDCContants.PAGEID_QLDC_MAN_HINH_CHINH %>"/>
</portlet:renderURL> --%>



<h2 class="tle-Content">
	<liferay-ui:message key="lich-su-thay-doi" />
</h2>
<div class="main-Content">
	<form method="POST" target="_blank" action="<%=QLDC_LichSuThayDoiURL.toString() %>" name="<portlet:namespace/>fmXemLichSuThayDoi" id="<portlet:namespace/>fmXemLichSuThayDoi">
		<aui:input name="<%= Constants.CMD %>" type="hidden" />
		<%
			long thongTinThayDoiId = ParamUtil.getLong(request, "thongTinThayDoi");
			System.out.println("xem lich su thay doi thongTinThayDoiId:"+ thongTinThayDoiId);
			ThongTinThayDoiEnum thongTinThayDoiEnum = null;
			if(thongTinThayDoiId > 0){
				thongTinThayDoiEnum = ThongTinThayDoiEnum.getByValue(thongTinThayDoiId);
			}
			List<LichSuDTO> lichSuDTOs = null;
			if( /* Validator.isNotNull(congDanDTO) && */ Validator.isNotNull(thongTinThayDoiEnum)){
				System.out.println("thongTinThayDoi ThongTinThayDoiEnum"+ thongTinThayDoiEnum.getKey() +" >" + thongTinThayDoiEnum.getValue());
				lichSuDTOs = UtilsData.getLichSu(soDinhDanhCaNhan, thongTinThayDoiId, request.getLocale(), portletConfig);
			}
		%>
		<table class="gridnormal">
			<tr>
				<td>
					<liferay-ui:message key="truong-thong-tin-thay-doi" />
				</td>
				
				<td>
					<select  id="<portlet:namespace/>thongTinThayDoi"  name="<portlet:namespace/>thongTinThayDoi">
						<option value="0"><liferay-ui:message key="chon-thong-tin-thay-doi" /></option>
						<%
							for(ThongTinThayDoiEnum enumThongTin : ThongTinThayDoiEnum.values()){
						%>
							<option value="<%=enumThongTin.getValue()%>"
							<%=(enumThongTin.getValue() == thongTinThayDoiId) ? "selected=selected" : ""%>><%=LanguageUtil.get(portletConfig, request.getLocale(), enumThongTin.getKey())%></option>
						<%
							} 
						%>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<liferay-ui:message key="so-dinh-danh-ca-nhan" />
				</td>
				<td>
					<%= soDinhDanhCaNhan %>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="button" class="btn btn-primary" onclick="LichSuThayDoi_Tim();" value="<liferay-ui:message key="tim" />" id="<portlet:namespace/>dtlcmnd_tim" /> 
					<input type="button" class="btn btn-primary" onclick="LichSuThayDoi_XuatVanBan();" value="<liferay-ui:message key="in-lich-su-thay-doi" />" id="<portlet:namespace/>dtlcmnd_xuat_van_ban" />
					<input type="button" class="btn" onclick="LichSuThayDoi_Thoat();" value="<liferay-ui:message key="thoat" />" id="<portlet:namespace/>dtlcmnd_thoat" /> 
				</td>
			</tr>
		</table>
		<%
			if(Validator.isNotNull(lichSuDTOs) && lichSuDTOs.size() > 0){
		%>
			<table>
				<thead class="table-columns">
					<tr>
						<td class="aui-w5">
							<liferay-ui:message key="stt" />
						</td>
						<td class="aui-w10">
							<liferay-ui:message key="truong-thay-doi" />
						</td>
						<td class="aui-w15">
							<liferay-ui:message key="ngay-thay-doi" />
						</td>
						<%-- <td class="aui-w20">
							<liferay-ui:message key="can-bo-thuc-hien-thay-doi" />
						</td> --%>
						<td class="aui-w20">
							<liferay-ui:message key="gia-tri-cu" />
						</td>
						<td class="aui-w20">
							<liferay-ui:message key="gia-tri-moi" />
						</td>
						<td class="aui-w10">
							<liferay-ui:message key="chu-thich" />
						</td>
					</tr>
				</thead>
				<tbody class="table-data">
					<%
						String _truongThayDoi = LanguageUtil.get(portletConfig, request.getLocale(), thongTinThayDoiEnum.getKey());
						for(int i=0; i < lichSuDTOs.size(); i++){
					%>		
						<tr>
							<td><%= (i+1)+"" %></td>
							<td><%=_truongThayDoi %></td>
							<td><%=lichSuDTOs.get(i).getNgayThayDoi()%></td>
							<%-- <td><%=lichSuDTOs.get(i).getCanBoThucHien() %></td> --%>
							<td><%=	lichSuDTOs.get(i).getGiaTriMoi()%></td>
							<td><%=	lichSuDTOs.get(i).getGiaTriCu()%></td>
							<td><%=	lichSuDTOs.get(i).getChuThich()%></td>
						</tr>
					<%
						}
					%>
				</tbody>
			</table>
		<%
			} 
		%>
	</form>
</div>


<script type="text/javascript">


function LichSuThayDoi_Tim(){
	$("#<portlet:namespace/>fmXemLichSuThayDoi").submit(); 
	$('#<portlet:namespace/>fmXemLichSuThayDoi').removeAttr("target");
	$('#<portlet:namespace/>fmXemLichSuThayDoi').removeAttr("action");
	$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.TIM%>');
	$("#<portlet:namespace/>fmXemLichSuThayDoi").attr('onsubmit', 'return true;');
	$("#<portlet:namespace/>fmXemLichSuThayDoi").submit();
	
};
function LichSuThayDoi_XuatVanBan(){
	console.log('LichSuThayDoi_XuatVanBan');
	showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
		if (index == 0)
		{
			$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.IN%>');
			$("#<portlet:namespace/>fmXemLichSuThayDoi").attr('action', '<%=QLDC_LichSuThayDoiURL.toString() %>');
			$("#<portlet:namespace/>fmXemLichSuThayDoi").attr('target', '_blank');
			$("#<portlet:namespace/>fmXemLichSuThayDoi").submit();
		}
	});
};
function LSTD_Thoat(){
	$('#<portlet:namespace/>fmXemLichSuThayDoi').removeAttr("target");
	$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.THOAT%>');
	$("#<portlet:namespace/>fmXemLichSuThayDoi").attr('action', '<%=QLDC_LichSuThayDoiURL.toString() %>');
	$("#<portlet:namespace/>fmXemLichSuThayDoi").submit();
};
</script>